<template>
	<view class="about" :style="{paddingTop: safeArea_top + 'px'}">
		<view class="head">
			<view class="back" @click="back">
				<uni-icons type="arrow-left" size="30"></uni-icons>
			</view>
			<view class="title">
				资质证书
			</view>
			<view></view>
		</view>
		
		<view class="container">
			<view class="content">
				<view class="title">
					输入验证码查看证照信息
				</view>
				
				<view class="validate">
					<input v-model="validate" class="uni-input" placeholder="请输入验证码" />
					<canvas style="width:120px;height: 30px;" canvas-id="canvas" @click="refresh"></canvas>
				</view>
				
				<view class="find" :class="is_right?'':'disabled'" @click="sumbit">
					查询
				</view>
			</view>
			
		</view>
		
	</view>
</template>

<script>
	import { Mcaptcha } from '@/utils/mcaptcha'
	export default {
		data(){
			return {
			   validate: '',
			   mcaptcha: null,
			   safeArea_top: '',
			   form: {
				   scene: "register",
				   captcha: ""
			   },
			   technician_id: ''
			}
		},
		onReady(){
			this.mcaptcha = new Mcaptcha({
				el: 'canvas',
				width: 120,
				height: 30,
				createCodeImg: ""
			}, 6);
		},
		onLoad(option) {
		   const safeArea = uni.getStorageSync("safeArea");
		   this.safeArea_top = safeArea.top + 15;
		   
		   this.technician_id = option.id
		},
		computed: {
			is_right(){
				if(this.validate.length === 6){
					return true
				}
				return false
			}
		},
		methods:{
			back(){
				uni.navigateBack()
			},
			refresh(){
				// 刷新
				this.mcaptcha.refresh()
			},
			sumbit(){
				if(!this.is_right) return
				const isRight = this.mcaptcha.validate(this.validate)
				if(isRight){
					// 导航
					uni.redirectTo({
					  url: "/bundle/pages/home/teinfo?id=" + this.technician_id,
					});
				}else{
					uni.showToast({
						title: '验证码输入错误',
						icon: 'none'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.about{
		background-color: #fff;
		.head{
			position: relative;
			display: flex;
			justify-content: center;
			align-items: center;
			padding-bottom: 30rpx;
			.back{
				position: absolute;
				left: 30rpx;
			}
			.title{
				font-size: 32rpx;
				font-weight: 500;
			}
		}
		
		.container{
			padding: 0 60rpx;
			background-color: #f5f6f8;
			
			.content{
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				.title{
					padding: 120rpx 0;
					font-weight: 600;
				}
				.validate{
					background-color: #fff;
					padding: 30rpx;
					border-radius: 16rpx;
					display: flex;
					align-items: center;
				}
				
				.find{
					margin-top: 60rpx;
					background-color: #38987c;
					width: 100%;
					text-align: center;
					padding: 30rpx;
					color: #fff;
					border-radius: 20rpx;
				}
			}
		}
	}
	.disabled{
		background-color: #A8C0B8 !important;
	}
</style>